package kr.co.mstyleshop.android.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;

public class BannerImagesJsonSupplier {
	
	public static ArrayList<Map<String, String>> findAllBannerImages(String url, Context context) {
		ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();

		String responseText = HttpUtils.get(url, context);

		try {
			JSONArray jsonArray = new JSONArray(responseText);
			int size = jsonArray.length();

			Map<String, String> image = null;
			JSONObject obj = null;
			for (int i = 0; i < size; i++) {
				obj = jsonArray.getJSONObject(i);
				image = new HashMap<String, String>();
				image.put("title", obj.getString("title"));
				image.put("url", obj.getString("url"));
				image.put("link", obj.getString("link"));
				image.put("width", obj.getString("width"));
				image.put("height", obj.getString("height"));

				list.add(image);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return list;
	}
}
